<?php require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('admingroup_update'); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>添加管理组</title>
<link href="templates/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="templates/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/jquery.nicescroll.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/Validform_v5.3.2_min.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/laymain.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/common.js"></script>
<script type="text/javascript">
    $(function () {
        //初始化表单验证
        $("#form").initValidform();
        //是否启用权限
        if ($("#ddlRoleType").find("option:selected").attr("value") == 1) {
            $(".border-table").find("input[type='checkbox']").prop("disabled", true);
        }
        $("#ddlRoleType").change(function () {
            if ($(this).find("option:selected").attr("value") == 1) {
                $(".border-table").find("input[type='checkbox']").prop("checked", false);
                $(".border-table").find("input[type='checkbox']").prop("disabled", true);
            } else {
                $(".border-table").find("input[type='checkbox']").prop("disabled", false);
            }
        });
        //权限全选
        $("input[name='checkAll']").click(function () {
            if ($(this).prop("checked") == true) {
                $(this).parent().siblings("td").find("input[type='checkbox']").prop("checked", true);
            } else {
                $(this).parent().siblings("td").find("input[type='checkbox']").prop("checked", false);
            }
        });
    });
</script>
</head>

<body class="mainbody">

<!--导航栏-->
<div class="location">
  <a href="admingroup" class="back"><i></i><span>返回列表页</span></a>
  <a href="home.php" class="home"><i></i><span>首页</span></a>
  <i class="arrow"></i>
  <a href="admingroup.php"><span>管理组</span></a>
  <i class="arrow"></i>
  <span>添加管理组</span>
   <a href="javascript:location.reload();" class="reload">刷新</a>
</div>
<div class="line10"></div>
<!--/导航栏-->

<!--内容-->
<div id="floatHead" class="content-tab-wrap">
  <div class="content-tab">
    <div class="content-tab-ul-wrap">
      <ul>
        <li><a class="selected" href="javascript:;">编辑角色信息</a></li>
      </ul>
    </div>
  </div>
</div>
<form name="form" id="form" method="post" action="admingroup_save.php">
<div class="tab-content">
  <dl>
    <dt>管理组名称</dt>
    <dd><input name="groupname" type="text" value="" id="groupname" class="input normal" datatype="*"  sucmsg="" /> <span class="Validform_checktip">*角色中文名称，100字符内</span></dd>
  </dl>  
  <dl>
    <dt>管理组描述：</dt>
    <dd><textarea name="description" id="description" datatype="" class="input normal" style="margin:7px 0;"></textarea> <span class="Validform_checktip"></span></dd>
  </dl> 
  <dl>
    <dt>默认进入站：</dt>
    <dd><div class="rule-multi-radio multi-radio">
          <span id="">
		  <?php
				$dosql->Execute("SELECT * FROM `#@__site` ORDER BY `id` ASC");
				while($row = $dosql->GetArray())
				{
					if($row['id'] == 1)
						$checked = 'checked="checked"';
					else
						$checked = '';
					echo '<input type="radio" id="groupsite'.$row['id'].'" name="groupsite" value="'.$row['id'].'" '.$checked.' /><label for="groupsite'.$row['id'].'">'.$row['sitename'].'</label>';
				}
			?>
		
		  </span>
      </div> <span class="Validform_checktip">*登录成功后自动进入的站点</span></dd>
  </dl> 
  <dl>
    <dt>是否启用：</dt>
    <dd> <div class="rule-single-checkbox">
          <input id="checkinfo" type="checkbox"name="checkinfo" value="true" checked="checked" />
      </div><span class="Validform_checktip">管理组状态</span></dd>
  </dl>   
  </div>
<div class="tab-content">    
  <dl>
    <dt>模块权限</dt>
    <dd>
      <table border="0" cellspacing="0" cellpadding="0" class="border-table ltable2" width="98%">
        <thead>
          <tr>
            <th width="30%">导航名称</th>
            <th>权限分配</th>
            <th width="10%">全选</th>
          </tr>
        </thead>
        <tbody>
          <?php 
		  	//循环栏目函数
	function Show($id=0, $i=0)
	{
		global $dosql,$cfg_siteid,$cfg_adminlevel;
		$dosql->Execute("SELECT * FROM `#@__navigation` WHERE `parentid`=$id ORDER BY orderid,id ASC", $id);
		while($row = $dosql->GetArray($id))
		{
				$classname = '';
				//设置空格
			for($n = 1; $n < $i; $n++)
				$classname .= '&nbsp;&nbsp;';
		
				$classname .= '<span class="folder-line"></span><span class="folder-open"></span>&nbsp;'.$row['classname'];

				?>	
				    <tr>
            <td style="white-space:nowrap;word-break:break-all;overflow:hidden;">
              <?php echo $classname; ?>
            </td>
            <td>
              <span id="" class="cbllist">
			  <?php 
				$actionType = explode(',',$row['action_type']);
	 
			$key=0;
			foreach($actionType as $value)
			{	$key++;
			
			
					switch($value)
				{
					case 'list':
						$valuev = '查看';
						break;  
					case 'add':
						$valuev = '添加';
						break;
					case 'update':
						$valuev = '修改';
						break;
					case 'del':
						$valuev = '删除';
						break;
					case 'Audit':
						$valuev = '审核';
						break;
					case 'Reply': 
						$valuev = '回复';
						break;
					case 'Cancel':
						$valuev = '取消';
						break;
					case 'Invalid':
						$valuev = '作废';
						break;
					case 'backup':
						$valuev = '备份';
						break;
					case 'restore':
						$valuev = '还原';
						break;
					default:
						$valuev = '';
				}
				if($value!='')echo '<input id="'.$row['id'].$key.'" type="checkbox" name="model[]" value="'.$row['idname'].'_'.$value.'" />
				<label for="'.$row['id'].$key.'">'.$valuev.'</label>';
			}
		
		  ?>
			  
			  </span>
            </td>
            <td align="center"><input name="checkAll" type="checkbox" /></td>
          </tr>
         
          	<?php
			Show($row['id'], $i+2);
		}
	}

	Show();


	//判断无记录样式
	if($dosql->GetTotalRow(0) == 0)
	{
		echo '<tr><td align="center" colspan="3">暂无记录</td></tr>';
	}
	
	

	?>
        </tbody>
      </table>
    </dd>
  </dl>
  </div>
<div class="tab-content">
   <dl>
    <dt>模型权限</dt>
    <dd>
	 <table border="0" cellspacing="0" cellpadding="0" class="border-table ltable2" width="98%"> <thead>
          <tr>
            <th width="30%">模型名称</th>
            <th>权限分配</th>
            <th width="10%">全选</th>
          </tr>
        </thead>
      <tbody>
	 <? if($id != 1)
			{
			?>
	  <tr>
	<td title="页面按钮权限">单页</td>
	<td >
		<span><input type="checkbox" name="model[]" id="model_info_list" value="info"  />
		<label for="model_info">查看</label></span>
		<span><input type="checkbox" name="model[]" id="model_info_add" value="info_add"  />
		<label for="model_info_add">添加</label></span>
		 <span><input type="checkbox" name="model[]" id="model_info_del" value="info_del"  />
		<label for="model_info_del">删除</label></span> 
	</td>
	<td align="center" ><input type="checkbox"  value=""  name="checkAll" /></td>
	</tr>
	<tr>
	<td title="页面按钮权限">列表</td>
	<td >
		<span><input type="checkbox" name="model[]" id="model_info" value="infolist" />
		<label for="model_infolist">查看</label></span>
		<span><input type="checkbox" name="model[]" id="model_info_add" value="infolist_add"  />
		<label for="model_infolist_add">添加</label></span>
		 <span><input type="checkbox" name="model[]" id="model_info_del" value="infolist_del"  />
		<label for="model_infolist_del">删除</label></span> 
	</td>
	<td align="center" ><input type="checkbox"  value=""  name="checkAll" /></td>
	</tr>
	

	<?php
                	//自定义模型
					$dosql->Execute("SELECT * FROM `#@__diymodel` ORDER BY ID ASC");
					while($modelrow = $dosql->GetArray()){
				?>	
				<tr>
	<td title="页面按钮权限" ><?php echo $modelrow['modeltitle'];?></td>
	<td >
		<span><input type="checkbox" name="model[]" id="model_<?php echo $modelrow['modelname'];?>" value="<?php echo $modelrow['modelname'];?>" />
		<label for="model_<?php echo $modelrow['modelname'];?>">查看</label></span>
		<span><input type="checkbox" name="model[]" id="model_<?php echo $modelrow['modelname'];?>_add" value="<?php echo $modelrow['modelname'];?>_add"  />
		<label for="model_<?php echo $modelrow['modelname'];?>_add">添加</label></span>
		 <span><input type="checkbox" name="model[]" id="model_<?php echo $modelrow['modelname'];?>_del" value="<?php echo $modelrow['modelname'];?>_del" />
		<label for="model_<?php echo $modelrow['modelname'];?>_del">删除</label></span> 
	</td>
	<td align="center" ><input type="checkbox"  value=""  name="checkAll" /></td>
	</tr>
				
                	
                <?php
					}
				?>
	<?php
			}
			else
			{
						echo '<tr><td colspan="3"><strong class="red">拥有所有权限</strong></td></tr>';
			}
			?>
	  </tbody>
		</table>
	</dd>
  </dl>
  </div>
<div class="tab-content">  
  <dl>
    <dt>栏目权限</dt>
    <dd>
	 <table border="0" cellspacing="0" cellpadding="0" class="border-table ltable2" width="98%"> <thead>
          <tr>
            <th width="30%">栏目名称</th>
            <th>权限分配</th>
            <th width="10%">全选</th>
          </tr>
        </thead>
        <tbody>
	<?php
		$dosql->Execute("SELECT * FROM `#@__site` ORDER BY `id` ASC");
			$i = 1;


				while($row2 = $dosql->GetArray())
				{
					echo '<tr><td colspan="3"><strong>'.$row2['sitename'].'</strong></td></tr>';
					Show2($row2['id'],$row['id']);
					$i++;
				}
			
			?>   </tbody>
		</table>
	</dd>
  </dl>
  
</div>
<!--/内容-->

<!--工具栏-->
<div class="page-footer">
  <div class="btn-wrap">
    <input type="submit" name="btnSubmit" value="提交保存" id="btnSubmit" class="btn" />
    <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);" />
	<input type="hidden" name="action" id="action" value="add" />
  </div>
</div>
<!--/工具栏-->
</form>
<?php 
function Show2($siteid=1, $groupid=0, $id=0, $i=1)
{
	global $dosql;

	$dosql->Execute("SELECT * FROM `#@__infoclass` WHERE `siteid`=$siteid AND `parentid`=$id ORDER BY `orderid` ASC", $id);
	$i++;

	while($row = $dosql->GetArray($id))
	{
		switch($row['infotype'])
		{
			case 0:
				$addurl   = 'info_update.php?id='.$row['id'];
				$infotype = ' <i title="栏目属于[单页]类型">[单页]</i>';
				break;
			case 1:
				$addurl   = 'infolist_add.php?cid='.$row['id'];
				$infotype = ' <i title="栏目属于[列表]类型">[列表]<i>';
				break;
			case 4:
				$addurl   = 'soft_add.php?cid='.$row['id'];
				$infotype = ' <i title="栏目属于[商品]类型">[商品]<i>';
				break;
			default:
				$r = $dosql->GetOne("SELECT * FROM `#@__diymodel` WHERE `id`=".$row['infotype']);
				if(isset($r) && is_array($r))
				{
					$addurl   = 'modeldata_add.php?m='.$r['modelname'].'&cid='.$row['id'];
					$infotype = ' <i title="栏目属于['.$r['modeltitle'].']类型">['.$r['modeltitle'].']</i>';
				}
				else
				{
					$addurl   = 'javascript:;';
					$infotype = ' 没有获取到类型';
				}
		}


		//设置$classname
			$classname = '';

			//设置空格
			for($n = 1; $n < $i; $n++)
				$classname .= '&nbsp;&nbsp;';
		
				$classname .= '<span class="folder-line"></span><span class="folder-open"></span>&nbsp;'.$row['classname'];

		//信息类型
		$classname .= '<span class="infoTypeTxt">'.$infotype.'</span>';
	
?>
<tr>
<td ><?php echo $classname; ?></td>
<td >
<span><input type="checkbox" id="list[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]" name="priv[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][]" value="list"  />
<label for="list[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]">查看</label></span> 
<span><input type="checkbox" id="add[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]" name="priv[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][]" value="add"  /> 
<label for="add[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]">添加</label></span> 
<span><input type="checkbox" id="update[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]" name="priv[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][]" value="update"  /> 
<label for="update[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]">修改</label></span> 
<span><input type="checkbox" id="del[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]" name="priv[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][]" value="del"  /> 
<label for="del[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]">删除</label></span>
<span><input type="checkbox" id="Audit[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]" name="priv[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][]" value="Audit"  />
<label for="Audit[<?php echo $siteid; ?>][<?php echo $row['id']; ?>][<?php echo $i;?>]">审核</label></span></td>
<td align="center" ><input type="checkbox"  value="<?php echo $siteid; ?>"  name="checkAll" /></td></tr>

<?php
		Show2($siteid, $groupid, $row['id'], $i+2);
	}
}
?>
</body>
</html>
